//
// Copyright (c) 2014, 保留所有权利。
//
// CstSum.java
//
// 作    者：王红燕
// 当前版本：1.0
// 2015年6月9日 下午6:18:29
//
// 
//
package com.vanke.agent.fix;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vanke.agent.ADataSource;
import com.vanke.agent.common.Cache;

/**
 * @author 王红燕
 * 
 */
public class CstSum {

	static Map<Long, Has> map;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		map = new HashMap<Long, Has>();
		long allCount = 0;
		long mobileCount = 0;
		long cardIdCount = 0;
		Connection con = ADataSource.getConnection(ADataSource.SCHEMA_BIZ);
		try {
			List<String> tables = Cache
			        .loadTables(con, "cst_cstmobilemapping_");
			for (String table : tables) {
				String sql = "select CstGUID from " + table;
				PreparedStatement pstmt = con.prepareStatement(sql);
				ResultSet rs = pstmt.executeQuery();
				while (rs.next()) {
					long cstGUID = rs.getLong(1);
					Has h = map.get(cstGUID);
					if (h == null) {
						h = new Has();
					}
					h.hasMobile = true;
					map.put(cstGUID, h);
				}
				rs.close();
				pstmt.close();
				System.out.println("total " + map.size() + " calced");
			} //
			tables = Cache.loadTables(con, "cst_cstcardidmapping_");
			for (String table : tables) {
				String sql = "select CstGUID from " + table;
				PreparedStatement pstmt = con.prepareStatement(sql);
				ResultSet rs = pstmt.executeQuery();
				while (rs.next()) {
					long cstGUID = rs.getLong(1);
					Has h = map.get(cstGUID);
					if (h == null) {
						h = new Has();
					}
					h.hasCardId = true;
					map.put(cstGUID, h);
				}
				rs.close();
				pstmt.close();
				System.out.println("total " + map.size() + " calced");
			} //
			Collection<Has> col = map.values();
			for (Has h : col) {
				if (h.hasCardId && h.hasMobile) {
					allCount++;
					continue;
				}
				if (h.hasCardId) {
					cardIdCount++;
					continue;
				}
				if (h.hasMobile) {
					mobileCount++;
					continue;
				}
				System.out.println("invalid count");
			}
			System.out.println("可信可联系：" + allCount);
			System.out.println("可信：" + cardIdCount);
			System.out.println("可联系:" + mobileCount);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ADataSource.close(con);
		}
	} //
}

class Has {
	public boolean hasMobile = false;
	public boolean hasCardId = false;
}
